﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLASCIICore
{
    public partial class GridBoard : UserControl
    {
        private List<GridColumn> columns = new List<GridColumn>();
        public GridColumn this[int index]
        {
            get
            {
                if (index >= 0 && index < columns.Count)
                {
                    return columns[index];
                }
                else
                {
                    return null;
                }
            }
        }
        public int Columns
        {
            get
            {
                return columns.Count;
            }
            set
            {
                if (value != columns.Count)
                {
                    while (value < columns.Count)
                    {
                        LayoutRoot.ColumnDefinitions.Remove(LayoutRoot.ColumnDefinitions[0]);
                        LayoutRoot.Children.Remove(columns[columns.Count - 1]);
                        columns.Remove(columns[columns.Count - 1]);
                    }
                    while (value > columns.Count)
                    {
                        LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
                        GridColumn column = new GridColumn();
                        LayoutRoot.Children.Add(column);
                        column.Column = columns.Count;
                        column.Rows = Rows;
                        column.Layers = Layers;
                        Grid.SetColumn(column, columns.Count);
                        columns.Add(column);
                    }
                }
            }
        }
        int rows = 0;
        public int Rows
        {
            get
            {
                return rows;
            }
            set
            {
                rows = value;
                foreach (GridColumn column in columns)
                {
                    column.Rows = rows;
                }
            }
        }
        int layers = 0;
        public int Layers
        {
            get
            {
                return layers;
            }
            set
            {
                if (value != layers)
                {
                    layers = value;
                    foreach (GridColumn column in columns)
                    {
                        column.Layers = layers;
                    }
                }
            }
        }

        public GridBoard()
        {
            InitializeComponent();
            //Columns = 40;
            //Rows = 30;
        }
    }
}
